function Sum(sum, currency) {

	this.sum = sum;
	this.currency = currency;
};

function Account() {

	var self = this;
	this.id = null;
	this.name = null;
	this.own = true;
	this.initialBalances = new Array();
	this.initialBalancesMap = {};
	this.balances = new Array();
	this.balancesMap = {};

	this.fromJson = function(json) {
		this.id = json.id;
		this.name = json.name;
		this.own = json.own;
		this.creationDate = new Date(json.creationDate);
		this.initialBalances.length = 0;
		$.each(json.initialBalances, function(index, initBalance) {
			self.initialBalances.push(new Sum(initBalance.sum, initBalance.currency));
			self.initialBalancesMap[initBalance.currency] = initBalance.sum;
		});
		this.balances.length = 0;
		$.each(json.balances, function(index, balance) {
			self.balances.push(new Sum(balance.sum, balance.currency));
			self.balancesMap[balance.currency] = balance.sum;
		});
		return this;
	};

	this.getInitialBalance = function(currency) {
		return this.initialBalancesMap[currency];
	};

	this.addInitialBalance = function(sum, currency) {
		if(!(currency in this.initialBalancesMap)) {
			this.initialBalances.push(new Sum(sum, currency));
			this.initialBalancesMap[currency] = sum;
			return true;
		}
		return false;
	};

	this.removeInitialBalance = function(currency) {
		if(currency in this.initialBalancesMap) {
			delete this.initialBalancesMap[currency];
			$.each(this.initialBalances, function(index, balance) {
				if(balance.currency === currency) {
					self.initialBalances.splice(index, 1);
					return false;
				}
			});
			return true;
		}
		return false;
	};

	this.getBalance = function(currency) {
		return this.balancesMap[currency];
	};

	this.clone = function () {
		//todo: implement account cloning
		return this;
	};
};